﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import = "jdbc.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "edu.thu.cs.*" %>
<%@ include file = "./../../login.jsp" %>
<%

if (email_status == null) {
	out.print("请先登录.");
	return;
}

JdbcDao mysql = new JdbcDao();

int aid = 0;
int raid = 0;
String rtitle = "";
HashMap<String, String> hm = null;

if (request.getParameter("aid") != null) {
	aid = Integer.parseInt(request.getParameter("aid"));
	hm = mysql.getArticleInfo(aid);
}

if (request.getParameter("raid") != null) {
	raid = Integer.parseInt(request.getParameter("raid"));
	rtitle = mysql.getPersonalInfo(email_status, "realname") + 
			"发表评论: " + mysql.getArticleInfo(raid).get("title");
}

String ptags = request.getParameter("tags");

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>ueditor</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript" charset="utf-8">
    function mysubmit() {
        var content = UE.getEditor('editor').getContent();
        var x = document.getElementById('content');
        x.value = content;
        document.getElementById('operator').value = 
        	'<%= (aid == 0 ? 
        			("class".equals(ptags) ? "newClass" : "postArticle") : 
        			"editArticle") %>';
        var form = document.getElementById('post');
        form.submit();
    }
    </script>

    <style type="text/css">
    
@import url(//fonts.googleapis.com/css?family=Open+Sans:300);
@import url(//fonts.googleapis.com/css?family=Open+Sans:400);
@import url(//fonts.googleapis.com/css?family=Open+Sans:400italic);
@import url(//fonts.googleapis.com/css?family=Open+Sans:600);
@import url(//fonts.googleapis.com/css?family=Open+Sans:700);
@import url(//fonts.googleapis.com/css?family=Open+Sans:800);
@import url(//fonts.googleapis.com/css?family=Asap);
@import url(//fonts.googleapis.com/css?family=Lato);
        div{
            width:100%;
        }
        #post {
			color: #ffc586;
        	margin-bottom:5px;
        }
        h1 {
			color: #ffc586;
        }
        #post p {
        	margin-bottom:0px;
			font-weight: bold;
        }
        #post lable {
			border-bottom: 3px solid #ffc586;
        }
        #post input {
			font: 12px/16px 'Open Sans';
			color: #ffc586;
			padding: 11px 0 7px 4px;
			width: 100%;
			border: none;
			margin: 0;
			-webkit-box-sizing: border-box;
			-moz-box-sizing: border-box;
			box-sizing: border-box;
			background: transparent;
		}
.btn_slide_wrapper {
position: relative;
display: inline-block;
overflow: hidden;
background: #feeaa3;
width: 216px;
margin-top: 30px;
}
.btn_main {
display: inline-block;
width: 216px;
font: 16px/16px 'Open Sans';
color: #58352a;
font-weight: 600;
text-transform: uppercase;
padding: 15px 0;
text-align: center;
letter-spacing: 1px;
}
    </style>
</head>
<body>
<div>
    <h1><%= (aid==0)? (raid==0?("class".equals(ptags) ? "新建课程 " : "发表文章"):"发表评论") : "修改文章" %></h1>
    <form id="post" action="./../../articleops.jsp" method="post" accept-charset="utf-8">
    	<lable>
    	<p><%= ("class".equals(ptags) ? "课程名 " : "标题") %></p>
    	<input type="text" name="title"
    	value="<%= (aid==0 ? 
    			((raid == 0) ?"" : rtitle) : 
    			StaticFunc.mysqlRealEscapeString(hm.get("title"))) %>"
    	>
    	</lable>
    	
    	<%
    	if ("class".equals(ptags)) {
    	%>
    	
    	<lable>
    	<p>学分</p>
    	<input type="text" name="credit"
    	value=""
    	>
    	</lable>
    	
    	<lable>
    	<p>主讲教师</p>
    	<input type="text" name="teacher"
    	value=""
    	>
    	</lable>
    	
    	<lable>
    	<p>本科生课容量</p>
    	<input type="text" name="numlimit"
    	value=""
    	>
    	</lable>
    	
    	<lable>
    	<p>上课时间 (yyyy-MM-dd HH:mm:ss)</p>
    	<input type="text" name="classdate"
    	value=""
    	>
    	</lable>
    	
    	<% }%>
    	
    	<lable>
    	<p>标签</p>
    	<input type="text" name="tags"
    	value="<%= (aid==0 ? 
    			((raid == 0) ? 
    					(ptags != null ? ptags : "") : 
    					"comment") :
    			StaticFunc.mysqlRealEscapeString(hm.get("tags"))) %>"
    	>
    	</lable>
    	<lable>
    	<p>评论</p>
    	<input type="text" name="commentto"
    	value="<%= (aid==0 ? 
    			((raid == 0) ?"" : new Integer(raid).toString()) : 
    			StaticFunc.mysqlRealEscapeString(hm.get("commentto"))) %>"
    	>
    	</lable>
    	<lable>
    	<p><%= ("class".equals(ptags) ? "课程描述" : "内容") %></p>
    	</lable>
    	<input id="content" type="text" name="content" style="display:none">
    	<input id="operator" type="text" name="operator" style="display:none">
    	<input id="articleid" type="text" name="articleid" style="display:none"
    	value="<%= aid %>"
    	>
    	<input id="hidehtml" type="text" name="hidehtml" style="display:none">
    </form>
    <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
</div>
<div id="btns">
	<a href="#" onclick="mysubmit()">
	<div class="btn_slide_wrapper">
    	<div class="btn_main">SUBMIT</div>
    </div>
	</a>
	<div style="display:none">
    <div>
        <button onclick="getAllHtml()">获得整个html的内容</button>
        <button onclick="getContent()">获得内容</button>
        <button onclick="setContent()">写入内容</button>
        <button onclick="setContent(true)">追加内容</button>
        <button onclick="getContentTxt()">获得纯文本</button>
        <button onclick="getPlainTxt()">获得带格式的纯文本</button>
        <button onclick="hasContent()">判断是否有内容</button>
        <button onclick="setFocus()">使编辑器获得焦点</button>
        <button onmousedown="isFocus(event)">编辑器是否获得焦点</button>
        <button onmousedown="setblur(event)" >编辑器失去焦点</button>

    </div>
    <div>
        <button onclick="getText()">获得当前选中的文本</button>
        <button onclick="insertHtml()">插入给定的内容</button>
        <button id="enable" onclick="setEnabled()">可以编辑</button>
        <button onclick="setDisabled()">不可编辑</button>
        <button onclick=" UE.getEditor('editor').setHide()">隐藏编辑器</button>
        <button onclick=" UE.getEditor('editor').setShow()">显示编辑器</button>
        <button onclick=" UE.getEditor('editor').setHeight(300)">设置高度为300默认关闭了自动长高</button>
    </div>

    <div>
        <button onclick="getLocalData()" >获取草稿箱内容</button>
        <button onclick="clearLocalData()" >清空草稿箱</button>
    </div>
	</div>
</div>

<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
	
    <%
    if (aid != 0) {
    %>
    var ct = "<%= StaticFunc.mysqlRealEscapeString(hm.get("content")) %>";
    setTimeout(function() {
    	ue = UE.getEditor('editor');
        ue.setContent(ct);
    }, 2000);
    <% } %>

    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent(ct, isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor('editor').focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor('editor').execCommand( "clearlocaldata" );
        alert("已清空草稿箱")
    }
</script>
</body>
</html>